package org.hhchat.leetcode.string;

import java.util.ArrayList;
import java.util.List;

/**
 * Created this one by HMH on 2017/11/26.
 */
public class code17_meduim {
    static class Solution {
        public List<String> letterCombinations(String digits) {
            if (digits.length() == 0) {
                return new ArrayList<>();
            }
            String[] button = {"", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
            List<String> list = new ArrayList<>();
            int[] cur = new int[digits.length()];
            for(int i = 0 ; i < digits.length(); i++){
                cur[i] = digits.charAt(i) - '0';
            }
            back(list, 0, cur, button, new StringBuilder());
            return list;
        }

        public void back(List<String> list, int index, int[] buttons, String[] buttonStr, StringBuilder str){
            if(index == buttons.length){
                list.add(str.toString());
                System.out.println(str.toString());
                return;
            }

            for(int i = 0; i < buttonStr[buttons[index]-1].length(); i++){
                str.append(buttonStr[buttons[index]-1].charAt(i));
                back(list, index+1, buttons, buttonStr, str);
                str.deleteCharAt(str.length()-1);
            }

        }
    }

}
